package service

import (
	"context"
	"microstudent/proto/teacher"
)

var teacherList []teacher.Teacher

type TeacherServiceHandler struct {
}

func (h *TeacherServiceHandler) Add(ctx context.Context, req *teacher.AddRequest, resp *teacher.AddResponse) error {
	var maxId int64 = 0
	for _, t := range teacherList {
		if t.Id > maxId {
			maxId = t.Id
		}
	}
	maxId++
	req.Teacher.Id = maxId
	teacherList = append(teacherList, *req.Teacher)
	return nil
}
func (h *TeacherServiceHandler) FindAll(ctx context.Context, req *teacher.FindAllRequest, resp *teacher.FindAllResponse) error {
	var rst []*teacher.Teacher
	for i, _ := range teacherList {
		rst = append(rst, &teacherList[i])
	}
	resp.Teachers = rst
	return nil
}
